<?php
namespace submodule\controllers;

use Yii;
use backend\models\LoginForm;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;


use yii\helpers\Url;
/**
 * Site controller
 */
class IndexController extends \submodule\base\BaseSubmoduleController
{
	public $layout = false;
	
	
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                //'only' => ['special-callback'],
                'rules' => [
                    [
                        'actions' => ['signup', 'index2', 'login'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout', 'index', 'index2', 'get-shortcut-menu'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
					
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    //'logout' => ['post'],
                ],
            ],
        ];
    }



    public function actionIndex()
    {
		//exit(Url::to(['user/bbb', 'id' => $this->id, 'aa'=>1111]));
		$data['menu']['parent'] = [
		    [
			'menuid'=>'system',
			'name' => '系统模块',
			'url' => ['models', 'type'=>'category'],
            ],
			[
			'menuid'=>'content',
			'name' => '内容模块',
			'url' => ['models', 'type'=>'category'],
            ],
			[
			'menuid'=>'category',
			'name' => '分类模块',
			'url' => ['models', 'type'=>'category'],
            ],
			[
			'menuid'=>'user',
			'name' => '用户模块',
			'url' => ['models', 'type'=>'user'],
            ],
			[
			'menuid'=>'goods',
			'name' => '商品模块',
			'url' => ['models', 'type'=>'goods'],
            ],
			[
			'menuid'=>'collect',
			'name' => '采集模块',
			'url' => ['models', 'type'=>'collect'],
            ],
			[
			'menuid'=>'forum',
			'name' => '社区模块',
			'url' => ['models', 'type'=>'forum'],
            ]
		
		];
		
		$data['menu']['data'] = [
		    [
			'parentid'=> 'system',
			'name' => '系统模块',
			'url' => ['models', 'type'=>'category'],
            'params' => '',
            ],
			[
			'parentid'=> 'content',
			'name' => '内容模块',
			'url' => ['models', 'type'=>'content'],
            ],
			[
			'parentid'=> 'category',
			'name' => '分类模块',
			'url' => ['models', 'type'=>'category'],
            ],
			[
			'parentid'=> 'user',
			'name' => '用户组管理',
			'url' => ['models', 'type'=>'category'],
            ],
			[
			'parentid'=>'goods',
			'name' => '订单模块',
			'url' => ['models', 'type'=>'order'],
            ],
			[
			'parentid'=>'goods',
			'name' => '支付模块',
			'url' => ['models', 'type'=>'pay'],
            ],
			[
			'parentid'=>'forum',
			'name' => '评论模块',
			'url' => ['models', 'type'=>'comment'],
            ],
			[
			'parentid'=>'forum',
			'name' => '点赞模块',
			'url' => ['models', 'type'=>'like'],
            ]
			
		
		];
		
        return $this->render('index', $data);
    }
	
	public function actionShortcutMenu(){
		
		$this->render('shortcutMenu');
		
	}
	
	public function actionUpdateShortcutMenu($menuid, $shortcut = 0){
		$sql = "update {{%backend_menu}} set shortcut = $shortcut where menuid = $menuid";
		$return = Yii::$app->db->createCommand($sql)->execute();
		Yii::app()->runController('mobo/menu/cache');
	}

	
	public function actionGetShortcutMenu($return = false){
		$menu = array();
		$data = Yii::$app->FileCache ->get('backend_menu');
		foreach($data as $k=>$v){
			if ($v['shortcut']) $menu[] = $v;
		}
		if($return){
			return $menu;
		}else{
		    echo json_encode($menu);
		}
		
	}
	
	
	public function actionIndex2()
    {
		
        return $this->render('index');
    }
	


}
